//
//  SXTitleBtn.m
//  Weibo1
//
//  Created by dfpo on 15/2/15.
//  Copyright (c) 2015年 dfpo. All rights reserved.
//

//2015-04-05 19:03:10.800 Weibo1[81208:1566633] 请求成功-{
//    uid = 3732967573,
//    expires_in = 115009,
//    access_token = 2.0065JdEE9ZUsXDc1cd0365d1f6gNcE,
//    remind_in = 115009
//    }

//    2015-04-05 19:03:38.845 Weibo1[81208:1566633] SXNewfeatureController-dealloc

//    2015-04-05 19:03:38.850 Weibo1[81208:1566633] 请求失败-Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: forbidden (403)" UserInfo=0x7f9ddad7fd50 {com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x7f9ddad26100> { URL: https://api.weibo.com/2/users/show.json?access_token=2.0065JdEE9ZUsXDc1cd0365d1f6gNcE&uid=3732967573 } { status code: 403, headers {
//        Content-Encoding = gzip,
//        Date = Sun, 05 Apr 2015 11:03:38 GMT,
//        Vary = Accept-Encoding,
//        Content-Type = application/json;charset=UTF-8,
//        api-server-ip = 10.75.0.170,
//        Server = nginx/1.6.1
//    } }, NSErrorFailingURLKey=https://api.weibo.com/2/users/show.json?access_token=2.0065JdEE9ZUsXDc1cd0365d1f6gNcE&uid=3732967573, com.alamofire.serialization.response.error.data=<7b226572 726f7222 3a226170 706c6963 6174696f 6e73206f 76657220 74686520 756e6175 64697465 64207573 65207265 73747269 6374696f 6e732122 2c226572 726f725f 636f6465 223a3231 3332312c 22726571 75657374 223a222f 322f7573 6572732f 73686f77 2e6a736f 6e227d>, NSLocalizedDescription=Request failed: forbidden (403)}
//    2015-04-05 19:03:38.851 Weibo1[81208:1566633] 请求失败-Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: forbidden (403)" UserInfo=0x7f9ddad5df50 {com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x7f9ddad87de0> { URL: https://api.weibo.com/2/statuses/friends_timeline.json?access_token=2.0065JdEE9ZUsXDc1cd0365d1f6gNcE } { status code: 403, headers {
//        Content-Encoding = gzip,
//        Date = Sun, 05 Apr 2015 11:03:38 GMT,
//        Vary = Accept-Encoding,
//        Content-Type = application/json;charset=UTF-8,
//        api-server-ip = 10.75.5.65,
//        Server = nginx/1.6.1
//    } }, NSErrorFailingURLKey=https://api.weibo.com/2/statuses/friends_timeline.json?access_token=2.0065JdEE9ZUsXDc1cd0365d1f6gNcE, com.alamofire.serialization.response.error.data=<7b226572 726f7222 3a226170 706c6963 6174696f 6e73206f 76657220 74686520 756e6175 64697465 64207573 65207265 73747269 6374696f 6e732122 2c226572 726f725f 636f6465 223a3231 3332312c 22726571 75657374 223a222f 322f7374 61747573 65732f66 7269656e 64735f74 696d656c 696e652e 6a736f6e 227d>, NSLocalizedDescription=Request failed: forbidden (403)}

//
//https://api.weibo.com/2/users/show.json?access_token=2.0065JdEE9ZUsXDc1cd0365d1f6gNcE&uid=3732967573
//{"error":"applications over the unaudited use restrictions!","error_code":21321,"request":"/2/users/show.json"}
//{“错误”:“在未经审计的应用程序使用限制!”,“error_code”:21321年,“请求”:“/ 2 /用户/ show.json”}



//https://api.weibo.com/2/statuses/friends_timeline.json?access_token=2.0065JdEE9ZUsXDc1cd0365d1f6gNcE
//{"error":"applications over the unaudited use restrictions!","error_code":21321,"request":"/2/statuses/friends_timeline.json"}
//{“错误”:“在未经审计的应用程序使用限制!”,“error_code”:21321年,“请求”:“/ 2 /状态/ friends_timeline.json " }

#import "SXTitleBtn.h"

@implementation SXTitleBtn

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        // 字体大小
        self.titleLabel.font = [UIFont systemFontOfSize:17];
        // 常规下的文字颜色
        [self setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        
        [self setImage:[UIImage imageNamed:@"navigationbar_arrow_down"] forState:UIControlStateNormal];
        [self setImage:[UIImage imageNamed:@"navigationbar_arrow_up"] forState:UIControlStateSelected];
        
    }
    return self;
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    // 如果仅仅是调整按钮内部titleLabel和imageView的位置，那么在layoutSubviews中单独设置位置即可
    
    // 1.计算titleLabel的frame
    self.titleLabel.x = self.imageView.x;
    
    // 2.计算imageView的frame
    self.imageView.x = CGRectGetMaxX(self.titleLabel.frame);
}

- (void)setTitle:(NSString *)title forState:(UIControlState)state
{
    [super setTitle:title forState:state];
    
    // 只要修改了文字，就让按钮重新计算自己的尺寸
    [self sizeToFit];
}

- (void)setImage:(UIImage *)image forState:(UIControlState)state
{
    [super setImage:image forState:state];
    
    // 只要修改了图片，就让按钮重新计算自己的尺寸
    [self sizeToFit];
}
@end
